layui.use(['jquery','form'],function () {
    var $ = layui.jquery;
    var form = layui.form;

    var str = [];
    var str2 = [];
    form.on('checkbox(authorityId)',function (data) {
        if(data.elem.checked==true){
            str.push(data.elem.value);
            for (var i = 0; i < str.length; i++) {
                for (var j = i+1; j < str.length; j++) {
                    if (str[i] == str[j]){
                        str.splice(j,1);
                        j--;
                    }
                }
            };
        }else{
            str2.push(data.elem.value);
            for (var i = 0; i < str2.length; i++) {
                for (var j = i+1; j < str2.length; j++) {
                    if (str2[i] == str2[j]){
                        str2.splice(j,1);
                        j--;
                    }
                }
            };
            for (var i = 0; i < str.length; i++) {
                for (var j = 0; j < str2.length; j++) {
                    if (str[i] == str2[j]){
                        str.splice(i,1);
                    }
                }
            };
        };
    });
    /* 确定开始 */
    queding = function queding(){
        var createId = localStorage.getItem('userId');
        var userId = $("#userId").val();
        var createDate =new Date();
        createDate = getTime(createDate);
        var json = {
            userId:userId,
            authorityIdd:str.toString(),
            createId:createId,
            createDate:createDate,
            type:2
        };
        $.ajax({
            type:"post",
            javaType:"json",
            data:{"userId":userId},
            url:"/jurisdiction/delUserStatus",
            success:function (data) {
                addStatus(json);
            }
        });
    };
    //顶部时间
    function getTime(date){
        var year = date.getFullYear(); //获取完整的年份(4位,1970-????)
        var month = date.getMonth()+1; //获取当前月份(0-11,0代表1月)
        var today = date.getDate(); //获取当前日(1-31)
        var hour = date.getHours(); //获取当前小时数(0-23)
        var minute = date.getMinutes(); //获取当前分钟数(0-59)
        var second = date.getSeconds(); //获取当前秒数(0-59)
        var nowTime;
        nowTime = year+'-'+fillZero(month)+'-'+fillZero(today)+' '+fillZero(hour)+':'+fillZero(minute)+':'+fillZero(second);
        return nowTime;
    };

    //时间的为零操作
    function fillZero(str){
        var realNum;
        if(str<10){
            realNum	= '0'+str;
        }else{
            realNum	= str;
        }
        return realNum;
    };
    function addStatus(json) {
        $.ajax({
            type:"post",
            javaType:"json",
            data:json,
            url:"/jurisdiction/addUserStatus",
            success:function (data) {
                if(data){
                    layer.msg("编辑成功");
                }else{
                    layer.msg("编辑失败");
                }
            }
        });
        var index  = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        parent.location.reload();
    };
    /* 确定结束 */


    /* 取消开始 */
    quxiao = function quxiao(){
        var index  = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    /* 取消结束 */
});